﻿using DemoQLKhoSX.DatabaseAccessLayer;
using DemoQLKhoSX.EntityClasses;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DemoQLKhoSX.BusinessLogicLayer
{
    class XuatBLO
    {
        private XuatDAO _XuatDAO;
        private KhachHangBLO _khachBLO = new KhachHangBLO();
        private HangBLO _hangBLO = new HangBLO();
        private ThuKhoBLO _thukhoBLO = new ThuKhoBLO();

        public XuatBLO()
        {
            _XuatDAO = new XuatDAO();
        }

        public List<XuatEntity> getXuatByID(string id)
        {
            List<XuatEntity> xuat = new List<XuatEntity>();
            DataTable tbl = new DataTable();
            tbl = _XuatDAO.searchByID(id);

            if (tbl != null)
                foreach (DataRow r in tbl.Rows)
                {
                    XuatEntity rXuat = new XuatEntity();
                    rXuat.IDXuat = id;
                    rXuat.IDThuKho = _thukhoBLO.getThuKhoByID(r["IDThuKho"].ToString());
                    rXuat.IDKhachHang = _khachBLO.getKhachHangByID(r["IDKhachHang"].ToString());
                    rXuat.IDHang = _hangBLO.getHangByID(r["IDHang"].ToString());
                    rXuat.NgayXuat = Convert.ToDateTime(r["NgayXuat"]);
                    rXuat.SoLuongXuat = Convert.ToInt32(r["SoLuongXuat"]);
                    xuat.Add(rXuat);
                }
            return xuat;
        }

        public bool InsertXuat(string idxuat, string idkhach, string idthukho, string idhang, DateTime ngayxuat, int soluongxuat)
        {
            bool rs = false;
            rs = _XuatDAO.addXuat(idxuat, idkhach, idthukho, idhang, ngayxuat, soluongxuat);

            return rs;
        }

    }
}
